#!/bin/sh
# postinst script for urd.bak
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


apachectl=`which apache2ctl`

if [ -z "$apachectl" ] ; then
    echo "apache2ctl not found"
    exit 1
fi
    
if [ ! -x "$apachectl" ] ; then
    echo "apache2ctl not executable"
    exit 1
fi


case "$1" in
    configure)
    if [ ! -f  /etc/apache2/conf.d/urd.conf ] ; then
   	    cp /usr/share/urd/urd.conf /etc/apache2/conf.d/ 
    fi
	chgrp -R www-data /usr/share/urd
	chmod -R g+w /usr/share/urd
	if [ -f "/usr/share/urd/.installed" ] ; then
# we dont any error to exit the script really....
		set +e 
		cur_wd=`pwd`
		cd /usr/share/urd/install/
        rm -f html/smarty/c_templates/default/*.tpl.php
		cd $cur_wd
		set -e 
	else 
		set +e 
		cur_wd=`pwd`
		cd /usr/share/urd/install/
		sh install.sh > /dev/null
		cd $cur_wd
		set -e 
	fi
    if [ -x "$apachectl" ] ; then
        $apachectl restart
    fi
	echo "Browse to http://localhost/urd to configure URD"
	
	;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


